home *** CD-ROM | disk | FTP | other *** search
-
- Doug here,
-
- > Yep, but I havn't tested it yet because of obvious reasons, but it depacks alright.
-
- > What 'obvious reasons'? ;-)
-
- I think Magnus should take a Falcon to his work. :)
-
- > I tried it last night (yes, I know I should go to bed much earlier) and it
- > looked very nice indeed. Great work Doug!
-
- Thanks. :)
-
- > Now, what needs to be done before the sprites can be put in?
-
- Well, as you know, it's not a straightforward job to drop the sprites in. I
- still have to do some more code to generate the sprite data for rendering, but
- that is not really a problem...
-
- > Since they're not in the BSP, I'd imagine (I haven't really thought about it)
- > that it isn't very obvious how they should be inserted at the right time
- > when drawing.
-
- That's exactly what the problem is going to be - we will have to 'intercept'
- each ssector as it comes out of the tree, and insert the sprites at this
- point - but I believe I have a solution which will minimize all of the 'thing'
- management overheads.
-
- If you can bear with me, I will describe the system I have in mind, which is
- a variation on a 'bucket array' using interleaved forward-linked lists. I think
- you will see that it makes our job a lot simpler, and provides the right information
- at exactly the right point in the program.
-
- ---
-
- Firstly, we have a simple 'sparse' array of pointers, one for each ssector.
- This pointer array is indexed using the ssector's own 16-bit index or 'name'.
-
- The pointers themselves are initialized to ZERO - which indicates that no
- objects are yet allocated to any ssector. There is a reason for not pointing
- the empty ssectors to a 'dummy' address instead, which I will explain later.
-
- Secondly, we have a link-buffer full of linked list information, describing
- which objects belong to which ssectors, with a terminator at the end of
- each list.
-
- Thirdly, we have a buffer full of object definitions - one per active object.
- These definitions consist of position information, intelligence 'states' and
- other object-specific stuff.
-
- Assuming that the current number of ALLOCATED objects is defined as N, we
- can create an object-allocation subroutine which does the following:-
-
- Allocate_Object:
-
- * index pointer array and check list-pointer for this ssector.
-
- * if pointer is VALID, then break the link at the very start
- of the linked list indicated by this pointer address, and store
- the link itself at offset (N*element_size) in the linked list buffer.
-
- * if pointer is INVALID, then 'create' a new linked list for this
- ssector by storing the object's link at offset (N*element_size)
- in the linked list buffer, and update the pointer array to point
- ot the new list, instead of zero. Terminate the forward link of
- the new object by either linking it to a dummy object or with a
- simple 0 / -1 terminator flag.
-
- * Increment N to reflect an increase in the number of total allocated
- objects. Store the ssector's index in the object's definition along
- with a back-link to aid deallocation of the object later on.
-
- This is a bit of an over-specific and detailed way to describe what
- is essentially a simple linked list maintenance job, but there are
- four good reasons for making it work in EXACTLY this way:-
-
- a) By looking up the list-pointer array for any ssector which comes
- off the BSP tree, we immediately have access to a linked list of
- ALL the objects contained in that sector, and that sector ONLY.
- This means we only draw what we can see, and nothing else.
-
- b) There can be as many as one entire linked list per ssector - which
- is a lot of lists - interleaving them in a single buffer this way
- allows us to conserve an immense amount of memory, which would be
- crippling if we reserved enough space for all objects, for all
- possible ssectors.
-
- c) Maintaining the sorted order of 'things' becomes part of the BSP's
- job, at no extra cost. We only have to sort a nominal 2-5 objects
- per VISIBLE ssector as opposed to tens or even hundreds per frame.
- Even if it adds up to the same number of objects, it's still faster
- to perform lots of well-divided sorts than one very big one.
-
- d) Maintaining the position of the 'things' themselves as they move
- from ssector to ssector is even easier - each time they cross a
- 2-sided linedef, you use the object's back-link to it's perent list
- to help you 'unlink' the object and use the index of the new ssector
- to let you 'insert' the object back into the start of the new list
- belonging to the target sector.
-
- I hope I have made my thoughts clear on the operation of this system,
- but I believe it will ensure sorting & printing overheads are kept
- very very close to zero.
-
- Of course, there may be additional improvements I have missed, and
- I would be glad to hear them. I just think this is a good place to
- start.
-
- Doug.
-
-
-